<template>
  <div class="tl-button-ref-container">
    <div v-show="display" :style="render === 'div' ? 'width:' + width + ';height:' + height : 'height:100vh;width:100vw;position:fixed;z-index:1020;top:0;left:0'">
      <tl-iframe ref="frame" id="repariRefIframe" @close="refClose" :transparentBg="true" @confirm="omsRepairConfirm" :url="url.baseUrl" :path="url.path" :render="render" :data="paramData" height="100%"></tl-iframe>
    </div>
  </div>
</template>

<script>
/** mixins */
/** 子组件 */
/** 工具类 */
/** VUE配置 */
export default {
  name: 'cosRepairRefComp',
  mixins: [],
  components: {},
  data() {
    return {
      display: false,
      url: {
        baseUrl: process.env.OMS_URL + '/dynamic',
        path: 'cos/cosRepairApply/refList'
        // baseUrl: process.env.MEET_URL + '/dynamic',
        // path: 'meet/meetManage/edit'
      },
      paramData: {},
      omsrepairid: {
        type: Number,
        default: 0
      },
      dynamicLoadedFlag: false
    }
  },
  props: {
    sourceType: {
      type: String,
      default: ''
    },
    sourceId: {
      type: Number,
      default: 0
    },
    sourceApp: {
      type: String,
      default: ''
    },
    disableEditSubmit: {
      type: Boolean,
      default: false
    },
    // 是否显示默认按钮
    isDisplayDefaultElement: {
      default: true,
      type: Boolean
    },
    buttonName: {
      type: String,
      default: '返修'
    },
    render: {
      type: String,
      default: 'el-dialog'
    },
    width: {
      type: String,
      default: '1000px'
    },
    height: {
      type: String,
      default: '700px'
    }
  },
  computed: {
    moreBtnMarginLeft() {
      return (document.body.clientWidth / 2 + 585) + 'px'
    }
  },
  methods: {
    // 参照关闭时调用
    refClose() {
      // 隐藏本Ifram
      this.display = false
    },
    // 返修单参照点击确认后调用此方法
    omsRepairConfirm(selectedRepairArr) {
      this.$tap
        .confirm('确认要关联此返修单吗，关联后不可修改！')
        .then((_) => {
          // 调用父组件方法保存选中的返修单
          this.$emit('repaiRefConfirm', selectedRepairArr)
          this.display = false
        })
        .catch((_) => {
        })
    },
    // Iframe加载完成后
    iframLoaded() {
      this.$emit('repairEditLoaded')
    },
    resetParamData() {
      this.paramData.id = this.omsRepairId
      this.paramData.isAdd = !this.omsRepairId
      this.paramData.visible = true
      this.paramData.microsourcetype = this.sourceType
      this.paramData.sourceid = this.sourceId
      this.paramData.sourceapp = this.sourceApp
      this.paramData.disableEditSubmit = this.disableEditSubmit
    },
    prefetch() {
      this.$refs.frame.prefetch()
    },
    openRepairEdit() {
      this.resetParamData()
      this.display = true
      this.$nextTick(() => {
        this.$refs.frame.prefetchLoad()
        this.iframLoaded()
      })
    }
  },
  mounted() {

  }
}
</script>
<style lang="scss" scoped>
/deep/.moreBtnClass {
  margin-top: 10px;
}
.btnGroupClass {
  background: white;
  min-width: 100px;
  padding-left: 25px;
}
</style>
